package com.jdk.demo.fileChannel.read;

import java.io.FileInputStream;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

public class Test2_3 {

	// 验证read方法将字节放入ByteBuffer当前位置
	public static void main(String[] args) throws Exception {
		FileInputStream fisRef = new FileInputStream("b.txt");
		FileChannel fileChannel = fisRef.getChannel();
		
		fileChannel.position(2);
		ByteBuffer bytebuffer = ByteBuffer.allocate(5);
		bytebuffer.position(3);
		
		fileChannel.read(bytebuffer);
		
		byte[] getByteArray = bytebuffer.array();
		for (int i = 0; i < getByteArray.length; i++) {
			if(getByteArray[i] == 0){
				System.out.print("空格");
			}else{
				System.out.print((char)getByteArray[i]);
			}
		}
		fileChannel.close();
		fisRef.close();
	}
	
}
